﻿/*
 * 作者：唐桥
 * 功能描述：数据库增删改
 * 时间：2018-01-19
 * 修改人：唐桥
 * 修改时间：2018-01-19 18:12
 *
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataAccess;
using System.Data.SqlClient;
using System.Data;
using Entity;


namespace DataBusiness
{
    public class LithologicSectionBLL
    {
        //读取所有字段(具体如下)
        //ID, WellNO, Horizon, MainLithology,WellDepth,LiThickness,StartLocation,EndLocation,UserID, InputDate
        public static DataSet GetLithologicSection()
        {
            string sSql = "select * from dbo.tb_LithologicSection";
            DataSet initDt;
            initDt = SqlHelper.QuerySql(sSql);
            initDt.Tables[0].Columns[0].ColumnName = "编号";
            initDt.Tables[0].Columns[1].ColumnName = "井号";
            initDt.Tables[0].Columns[2].ColumnName = "层位";
            initDt.Tables[0].Columns[3].ColumnName = "主要岩性";
            initDt.Tables[0].Columns[4].ColumnName = "底层井深(m)";
            initDt.Tables[0].Columns[5].ColumnName = "层位(m)";
            initDt.Tables[0].Columns[6].ColumnName = "开始位置";
            initDt.Tables[0].Columns[7].ColumnName = "结束位置";
            initDt.Tables[0].Columns[8].ColumnName = "添加人";
            initDt.Tables[0].Columns[9].ColumnName = "添加时间";
            return initDt;
        }
        /// <summary>添加岩性剖面信息 </summary>
        /// <param name="t">岩性剖面信息对象</param>
        /// <returns>返回所影响的数据行数</returns>
        public static int InsertLithologicSection(tb_LithologicSectionModel t)
        {
            //第一种方式 拼接sql语句字符串
            //string sSql = string.Format("Insert into tb_LithologicSection(ID, WellNO, Horizon, MainLithology,WellDepth,LiThickness,StartLocation,EndLocation,UserID, InputDate) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", t.ID, t.WellNO, t.Horizon, t.MainLithology,t.WellDepth,t.LiThickness,t.StartLocation,t.EndLocation,t.UserID, t.InputDate);
            //return SqlHelper.ExeSql(sSql);
            //第二种方式
            String sSql = "Insert into tb_LithologicSection(WellNo, Horizon, MainLithology,WellDepth,LiThickness,StartLocation,EndLocation,UserID, InputDate) values( @WellNo, @Horizon, @MainLithology,@WellDepth,@LiThickness,@StartLocation,@EndLocation,@UserID, @InputDate)";

            SqlParameter[] Paras = new SqlParameter[9];
            //Paras[0] = new SqlParameter("@ID", t.ID1);
            Paras[0] = new SqlParameter("@WellNo", t.WellNo1);
            Paras[1] = new SqlParameter("@Horizon", t.Horizon1);
            Paras[2] = new SqlParameter("@MainLithology", t.MainLithology1);
            Paras[3] = new SqlParameter("@WellDepth", t.WellDepth1);
            Paras[4] = new SqlParameter("@LiThickness", t.LiThickness1);
            Paras[5] = new SqlParameter("@StartLocation", t.StartLocation1);
            Paras[6] = new SqlParameter("@EndLocation", t.EndLocation1);
            Paras[7] = new SqlParameter("@UserID", t.UserID1);
            Paras[8] = new SqlParameter("@InputDate", t.InputDate1);
            return SqlHelper.ExeSql(sSql, Paras);
        }
        public static int DeleteLithologicSection(String sSql)
        {
            return SqlHelper.ExeSql(sSql);
        }
        /// <summary>修改岩性剖面信息 </summary>
        /// <param name="t">岩性剖面信息对象</param>
        /// <returns>返回所影响的数据行数</returns>
        public static int UpdateLithologicSection(tb_LithologicSectionModel t)
        {
            //第一种方式
            //  sSql = string.Format("update tb_LithologicSection set WellNO='{0}', Horizon='{1}', MainLithology='{2}',WellDepth='{3}',LiThickness='{4}',StartLocation='{5}',EndLocation='{6}',UserID='{7}', InputDate='{8}' where ID='{9}' ",t.WellNO1, Convert.ToInt32(t.Horizon1), t.MainLithology1,Convert.ToDecimal(t.WellDepth1),Convert.ToDecimal(t.LiThickness1),Convert.ToDecimal(t.StartLocation1),Convert.ToDecimal(t.EndLocation1),t.UserID1, t.InputDate1,t.ID1);
            //  return SqlHelper.ExeSql(sSql);
            //第二种方式      
            String sSql = "update tb_LithologicSection set  WellNo=@WellNo,Horizon=@Horizon, MainLithology=@MainLithology,WellDepth=@WellDepth,LiThickness=@LiThickness,StartLocation=@StartLocation,EndLocation=@EndLocation,UserID=@UserID, InputDate= @InputDate where ID=@ID";
            SqlParameter[] Paras = new SqlParameter[10];
            Paras[0] = new SqlParameter("@ID", t.ID1);
            Paras[1] = new SqlParameter("@WellNo", t.WellNo1);
            Paras[2] = new SqlParameter("@Horizon", t.Horizon1);
            Paras[3] = new SqlParameter("@MainLithology", t.MainLithology1);
            Paras[4] = new SqlParameter("@WellDepth", t.WellDepth1);
            Paras[5] = new SqlParameter("@LiThickness", t.LiThickness1);
            Paras[6] = new SqlParameter("@StartLocation", t.StartLocation1);
            Paras[7] = new SqlParameter("@EndLocation", t.EndLocation1);
            Paras[8] = new SqlParameter("@UserID", t.UserID1);
            Paras[9] = new SqlParameter("@InputDate", t.InputDate1);
            return SqlHelper.ExeSql(sSql, Paras);
        }
    }
}

